import React, { useState ,useImperativeHandle} from 'react';
import { Modal,message} from 'antd';
import request from '../../utils/request';

export default function DeleteUser(props) {
  const [isModalVisible, setIsModalVisible] = useState(false);
  const [userID,setUserID] = useState(0)
   //用useImperativeHandle暴露一些外部ref能访问的属性
   useImperativeHandle(props.onRef, () => {
    return {
      setIsModalVisible,
      setUserID
    };
  });
  //确定删除
  const handleOk = async() => {
    const data = await request.delete(`/v1/user/${userID}`)
    console.log(data);
    setIsModalVisible(false);
    message.success('删除成功')
    props.getUsers()
  };
  //取消删除
  const handleCancel = () => {
    setIsModalVisible(false);
    message.info('已取消删除')
  };
  return (
    <Modal title="是否删除该用户" visible={isModalVisible} onOk={handleOk} onCancel={handleCancel} okText='确认删除' cancelText='取消' >
        <p style={{color:'red'}}>一旦删除将不可逆转</p>
    </Modal>
  )
}
